package com.changgou.item.controller;

import com.changgou.common.vo.Result;
import com.changgou.item.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/page")
public class PageController {

    @Autowired
    private PageService pageService;

    /**
    * 根据商品spu id生成静态页面
    * @param spuId 商品spu id
    */
    @GetMapping("/createHtml/{spuId}")
    public Result createHtml(@PathVariable Long spuId){
        try {
            pageService.createHtml(spuId);
            return new Result("生成静态页面成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result("生成静态页面失败！");
    }

    /**
     * 根据商品spu id删除静态页面
     * @param spuId 商品spu id
     * @return 操作结果
     */
    @GetMapping("/deleteHtml/{spuId}")
    public Result deleteHtml(@PathVariable Long spuId){
        try {
            pageService.deleteHtml(spuId);
            return new Result("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result("删除失败！");
    }

}
